export default class Router {

    constructor(url) {
        this._routes = {}
        this._root = '/'

        window.addEventListener('load', this.route(), false)
        window.addEventListener('hashchange', this.resolve(), false)
    }

    route = (path, cb) => {
        cb ? this._routes[path] = cb : _ => {}
    }

    resolve = () => {
        location.hash ? this._root = location.hash.slice(1) : 0
        typeof this._routes[this._root] === 'function' && this._routes[this._root]()
    }

}